#ifndef RTTIMERWRAPPER_H
#define RTTIMERWRAPPER_H

#include "RtBase.h"
#include "RtReactorInterface.h"

class CTimeValue;
class CRtTimerWrapper;

class /*RT_API_EXPORT*/ CRtTimerWrapperSink
{
public:
	virtual void OnTimer(CRtTimerWrapper* aId) = 0;

protected:
	virtual ~CRtTimerWrapperSink() {}
};

class RT_API_EXPORT CRtTimerWrapper : public IRtTimerHandler
{
public:
	CRtTimerWrapper();
	virtual ~CRtTimerWrapper();

	/// Schedule an timer that will expire after <aInterval> for <aCount> times. 
	/// if <aCount> is 0, schedule infinite times.
	RtResult Schedule(
		CRtTimerWrapperSink* aSink,
		const CRtTimeValue &aInterval,
		DWORD aCount = 0);

	/// Cancel the timer.
	RtResult Cancel();
	BOOL IsScheduled() { return m_bScheduled; }

protected:
	virtual void OnTimeout(const CRtTimeValue &aCurTime, LPVOID aArg);

private:
	BOOL m_bScheduled;
	IRtTimerQueue *m_pTimerQueue;
	DWORD m_count;
};

#endif // !RTTIMERWRAPPER_H
